<?php
namespace plugins\goods\model;

use think\Model;

class GoodsAuditModel extends Model
{
    /**
     * 日志
     *  field   字段名
     *  id      该字段id值
     * status   状态：1审核中，2通过，3驳回
     * reason   驳回原因
     * 返回布尔值
     */
    public function journal($field, $id, $status = 1, $reason = null)
    {
        $data = [
            "$field" => $id,
            'status' => $status,
            'time'   => time(),
            'reason' => $reason,
        ];
        $info = $this->save($data);
        // $info = db('audit')->insert($data);
        if ($info) {
            return true;
        }
        return false;
    }


    /**
     * 审核开启状态 1开启 2关闭
     */
    public static function getAuditIsOpen()
    {
        $config = static::getAuditConfig();
        $is_open = "2";
        if (!empty($config['audit_open'])) {
            $is_open = $config['audit_open'];
        }
        return $is_open;
    }

    /**
     * 审核配置
     */
    public static function getAuditConfig()
    {
        $config = getModuleConfig( 'goods' , "config/conf", "audit_set.json" );
        $config = json_decode( $config , true );
        return $config;
    }





}
